#include "trap.h"
    .set mips32
    .globl main
    .text
main:
#SUB
    # 16-9=7    一般情况
    li $t0, 0x10
    li $t1, 0x9
    sub $s0, $t0, $t1               # $s0 = 0x00000007
    sltu $s1, $s0, $t1              # $s1 = 0x00000001

    # 16-(-9)=25    正-负
    li $t2, 0xfffffff7
    sub $s2, $t0, $t2               # $s2 = 0x00000019
    sltiu $s3, $s2, 0x0019          # $s3 = 0x00000000

    # 0xffffffff-0x00000009=0xfffffff6  负-正
    li $t3, 0xffffffff
    sub $s4, $t3, $t1               # $s4 = 0xfffffff6
    slt $s5, $s4, $t3              # $s5 = 0x00000001

    # 0xffffffff-(0xfffffff7)=0x00000008    负-负
    sub $s6, $t3, $t2               # $s6 = 0x00000008
    sltiu $s7, $s6, 0xffff          # $s7 = 0x00000001

    # 0x0-0xffffffff=0x00000001
    subu $a0, $zero, $t3            # $a0 = 0x00000001
    slti $a1, $t2, 0xffff           # $a1 = 0x00000001

    ####结果相加####
    add $a0, $a0, $s0
    add $a0, $a0, $s1
    add $a0, $a0, $s2
    add $a0, $a0, $s3
    add $a0, $a0, $s4
    add $a0, $a0, $s5
    add $a0, $a0, $s6
    add $a0, $a0, $s7
    add $a0, $a0, $a1
    #### $a0 = 0x00000023 ####

    # 16/9=1......7
    div $zero, $t0, $t1                    # $lo = 0x00000001  $hi = 0x00000007
    mfhi $s0
    mflo $s1

    # 0xffffffff*0xfffffff7=0x00000009
    mult $t3, $t2                          # $lo = 0x00000009  $hi = 0x00000000
    mfhi $s2
    mflo $s3

	# 0xffffffff*0x00000009=0xfffffffffffffff7
	mult $t3, $t1                          # $lo = 0xfffffff7  $hi = 0xffffffff
    mfhi $s4
    mflo $s5

	# 0xffffffff*0x0000000=0x0000000000000000
	multu $t3, $zero                       # $lo = hi = 0x00000000
    mfhi $s6
    mflo $s7

	# 0xffffffff*0x00000009=0x00000008fffffff7
	multu $t3, $t1                         # $lo = 0xfffffff7  $hi = 0x00000008
    mfhi $a1
    mflo $a2

    # 0xffffffff/0x000000010=0x0fffffff......0x0000000f
	divu $zero, $t3, $t0                   # $lo = 0x0fffffff  $hi = 0x0000000f
    mfhi $a3
    mflo $v0

    ####结果相加####
    add $a1, $a1, $s0
    add $a1, $a1, $s1
    add $a1, $a1, $s2
    add $a1, $a1, $s3
    add $a1, $a1, $s4
    add $a1, $a1, $s5
    add $a1, $a1, $s6
    add $a1, $a1, $s7
    add $a1, $a1, $a2
    add $a1, $a1, $a3
    add $a1, $a1, $v0
    #### $a1 = 0x10000014 ####

    li $v0, 0x2
	li $v1, 0x80000000
	sub $s0, $v0, $v1
	
SUB_OVERFLOW_2:
	sub $s1, $v1, $t1
	
	.org 0x380
	nop
    li $k0, 0x1
	sub $v0,$v0,$k0
	bgtz $v0, SUB_OVERFLOW_2

    HIT_GOOD_TRAP
